Skip to content

fix(local): warn when CodeUri path does not exist before mounting#9120

Merged
vicheey merged 2 commits into
aws:developfrom
cesar32az:warn-nonexistent-codeuri-local-invoke
Jul 16, 2026
Merged

fix(local): warn when CodeUri path does not exist before mounting#9120
vicheey merged 2 commits into
aws:developfrom
cesar32az:warn-nonexistent-codeuri-local-invoke

Conversation

@cesar32az

Copy link
Copy Markdown
Contributor

Which issue(s) does this change fix?

#1754

Why is this change necessary?

When running sam local invoke, start-api or start-lambda with a CodeUri (or layer ContentUri) that does not exist on the local machine, the path is silently mounted as an empty directory in the container. The invocation then fails with a secondary error inside the container (import/handler not found) that hides the real problem. Issue #1754 was marked open for contributors by a maintainer.

How does it address the issue?

LambdaRuntime._get_code_dir now logs a warning when the resolved code path does not exist, before the container is started:

Local code path '<path>' does not exist. It will be mounted as an empty directory in the container, which will likely cause the invocation to fail. Verify the CodeUri/ContentUri of your function or layer, or run 'sam build' if the path is a build artifact.

Since _get_code_dir is used both for function code and for layers (via _unarchived_layer), the warning covers both cases. Behavior is otherwise unchanged: the path is still returned as is, exactly as documented in the method docstring.

Verified end-to-end with Docker: sam local invoke on a template whose CodeUri points to a missing directory now prints the warning right after "Invoking app.handler (python3.12)".

What side effects does this change have?

None. Only a warning log line is added; no control flow changes. code_path values that exist (directories, zip/jar archives) behave exactly as before, and the full unit suite passes.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Review the generative AI contribution guidelines
  • Add input/output type hints to new functions/methods (no new functions; existing signature unchanged)
  • Write design document if needed (not needed: single warning log line)
  • Write/update unit tests (two new tests in TestLambdaRuntime_get_code_dir: warning emitted for a missing path, no warning for an existing path)
  • Write/update integration tests (not needed: log-only change, covered by unit tests and manual end-to-end verification with Docker)
  • Write/update functional tests if needed (not needed)
  • make pr passes (schema, black-check, ruff, mypy: no issues in 1375 files; unit suite: 9287 passed, coverage 94.16% >= 94%)
  • make update-reproducible-reqs if dependencies were changed (no dependency changes)
  • Write documentation (not needed: no user-facing interface change)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

When running sam local invoke, start-api or start-lambda with a
CodeUri (or layer ContentUri) that does not exist on the local
machine, the path was silently mounted as an empty directory in the
container. The invocation then failed with a secondary error (import
or handler not found) that hides the real problem.

Log a warning in LambdaRuntime._get_code_dir when the resolved code
path does not exist, pointing the user at the CodeUri/ContentUri and
suggesting sam build, so the root cause is visible before the
container starts.

Fixes aws#1754
@cesar32az
cesar32az requested a review from a team as a code owner July 7, 2026 20:55
@github-actions github-actions Bot added area/local/start-api sam local start-api command area/local/invoke sam local invoke command area/local/start-invoke pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jul 7, 2026
@vicheey
vicheey added this pull request to the merge queue Jul 16, 2026
Merged via the queue into aws:develop with commit d4c1835 Jul 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/local/invoke sam local invoke command area/local/start-api sam local start-api command area/local/start-invoke pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants